#include "StyleManager.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>

bool StyleManager::loadGlobalStyle(QApplication *app)
{
    if (!app) {
        qWarning() << "StyleManager::loadGlobalStyle: QApplication is null";
        return false;
    }
    
    QString styleContent = getStyleContent(":/styles/style.qss");
    if (styleContent.isEmpty()) {
        qWarning() << "StyleManager::loadGlobalStyle: Failed to load style file";
        return false;
    }
    
    applyStyle(app, styleContent);
    return true;
}

QString StyleManager::getStyleContent(const QString &stylePath)
{
    QFile styleFile(stylePath);
    if (!styleFile.open(QFile::ReadOnly | QFile::Text)) {
        qWarning() << "StyleManager::getStyleContent: Cannot open style file:" << stylePath;
        return QString();
    }
    
    QTextStream styleStream(&styleFile);
    QString content = styleStream.readAll();
    styleFile.close();
    
    return content;
}

void StyleManager::applyStyle(QApplication *app, const QString &styleContent)
{
    if (!app || styleContent.isEmpty()) {
        return;
    }
    
    app->setStyleSheet(styleContent);
}
